package com.miaostars.myaifriend;

import org.bukkit.entity.Villager;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.plugin.Plugin;

public class AIEntity implements org.bukkit.event.Listener {
    private final Plugin plugin;
    private final VoiceManager voiceManager;

    // 构造函数，初始化插件和语音管理器
    public AIEntity(Plugin plugin, VoiceManager voiceManager) {
        // 将插件赋值给成员变量plugin
        this.plugin = plugin;
        // 将语音管理器赋值给成员变量voiceManager
        this.voiceManager = voiceManager;
    }⁠⁠

    @org.bukkit.event.EventHandler
    public void onRightClick(PlayerInteractEntityEvent event) {
        // 检查是否为右键点击生物事件
        if (!(event.getRightClicked() instanceof Villager)) return;
        Villager npc = (Villager) event.getRightClicked();
        
        // 检查是否为配置的AI生物
        if (npc.getCustomName() != null && 
            npc.getCustomName().equals(plugin.getConfig().getString("creature_name"))) {
            // 打开对话GUI
            new DialogueGUI(event.getPlayer(), voiceManager).open();
            // 取消事件
            event.setCancelled(true);
        }
    }
}